home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / fixinc.ptx < prev    next >
Text File  |  1994-09-10  |  6KB  |  197 lines

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible
  3. # native Sequent DYNIX/ptx System V Release 3.2 system include files.
  4. # Copyright (C) 1994 Free Software Foundation, Inc.
  5. # Contributed by Bill Burton <billb@progress.com>
  6. # Portions adapted from fixinc.svr4 and fixincludes.
  7. #
  8. # This file is part of GNU CC.
  9. # GNU CC is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. # GNU CC is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU CC; see the file COPYING.  If not, write to
  19. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. #    This script munges the native include files provided with DYNIX/ptx
  22. #    so as to remove things which are violations of the ANSI C standard.
  23. #    This is done by first running fixinc.svr4 which does most of the
  24. #    work.  A few includes have fixes made to them afterwards  by this
  25. #    script.  Once munged, the resulting new system include files are
  26. #    placed in a directory that GNU C will search *before* searching the
  27. #    /usr/include directory. This script should work properly for most
  28. #    DYNIX/ptx systems.  For other types of systems, you should use the
  29. #    `fixincludes' script instead.
  30. #
  31. #    See README-fixinc for more information.
  32.  
  33. # Directory containing the original header files.
  34. INPUT=${2-${INPUT-/usr/include}}
  35.  
  36. # Fail if no arg to specify a directory for the output.
  37. if [ x$1 = x ]
  38. then echo fixincludes: no output directory specified
  39. exit 1
  40. fi
  41.  
  42. # Directory in which to store the results.
  43. LIB=${1?"fixincludes: output directory not specified"}
  44.  
  45. # Make sure it exists.
  46. if [ ! -d $LIB ]; then
  47.   mkdir $LIB || exit 1
  48. fi
  49.  
  50. ORIG_DIR=`pwd`
  51.  
  52. # Make LIB absolute if it is relative.
  53. # Don't do this if not necessary, since may screw up automounters.
  54. case $LIB in
  55. /*)
  56.     ;;
  57. *)
  58.      LIB=$ORIG_DIR/$LIB
  59.     ;;
  60. esac
  61.  
  62. echo 'Running fixinc.svr4'
  63. # DYNIX/ptx has dirname so this is no problem
  64. `dirname $0`/fixinc.svr4 $*
  65. echo 'Finished fixinc.svr4'
  66.  
  67. echo 'Building fixincludes in ' ${LIB}
  68.  
  69. # Copied from fixincludes.
  70. # Don't use or define the name va_list in stdio.h.
  71. # This is for ANSI and also to interoperate properly with gcc's varargs.h.
  72. file=stdio.h
  73. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  74.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  75.   chmod +w ${LIB}/$file 2>/dev/null
  76.   chmod a+r ${LIB}/$file 2>/dev/null
  77. fi
  78.  
  79. if [ -r ${LIB}/$file ]; then
  80.   echo Fixing $file, use of va_list
  81.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  82.   (echo "#define __need___va_list"
  83.    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  84.   # Use __gnuc_va_list in arg types in place of va_list.
  85.   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  86.   # trailing parentheses and semicolon save all other systems from this.
  87.   # Define __va_list__ (something harmless and unused) instead of va_list.
  88.   # Don't claim to have defined va_list.
  89.   sed -e 's@ va_list @ __gnuc_va_list @' \
  90.       -e 's@ va_list)@ __gnuc_va_list)@' \
  91.       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
  92.       -e 's@ va_list@ __va_list__@' \
  93.       -e 's@\*va_list@*__va_list__@' \
  94.       -e 's@ __va_list)@ __gnuc_va_list)@' \
  95.       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
  96.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  97.       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
  98.     ${LIB}/$file >> ${LIB}/${file}.sed
  99.   
  100.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  101.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  102.     rm -f ${LIB}/$file
  103.   fi
  104. fi
  105.  
  106. # In pwd.h, PTX 1.x needs stdio.h included since FILE * was added in a
  107. # prototype later on in the file.
  108. file=pwd.h
  109. base=`basename $file`
  110. if [ -r ${LIB}/$file ]; then
  111.   file_to_fix=${LIB}/$file
  112. else
  113.   if [ -r ${INPUT}/$file ]; then
  114.     file_to_fix=${INPUT}/$file
  115.   else
  116.     file_to_fix=""
  117.   fi
  118. fi
  119. if [ \! -z "$file_to_fix" ]; then
  120.   echo Checking $file_to_fix
  121.   if grep stdio $file_to_fix > /dev/null; then
  122.     true
  123.   else
  124.     sed -e '/#include \<sys\types\.h\>/a\
  125. \
  126. #if defined(__STDC__) || defined(__cplusplus)\
  127. #include <stdio.h>\
  128. #endif  /* __STDC__ */' \
  129.     $file_to_fix > ${LIB}/${file}.sed
  130.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  131.     echo Fixed $file_to_fix
  132.   fi
  133. fi
  134.  
  135. # Copied from fixincludes.
  136. # math.h puts the declaration of matherr before the definition
  137. # of struct exception, so the prototype (added by fixproto) causes havoc.
  138. file=math.h
  139. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  140.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  141.   chmod +w ${LIB}/$file 2>/dev/null
  142.   chmod a+r ${LIB}/$file 2>/dev/null
  143. fi
  144.  
  145. if [ -r ${LIB}/$file ]; then
  146.   echo Fixing $file, matherr declaration
  147.   sed -e '/^struct exception/,$b' \
  148.       -e '/matherr/i\
  149. struct exception;
  150. '\
  151.     ${LIB}/$file > ${LIB}/${file}.sed
  152.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  153.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  154.     rm -f ${LIB}/$file
  155.   fi
  156. fi
  157.  
  158. # In netinet/in.h, the network byte swapping asm functions supported by the
  159. # native cc compiler on PTX 1.x and 2.x is not supported in gcc.  Instead,
  160. # include <sys/byteorder.h> written out by the fixinc.svr4 script which has
  161. # these same routines written in an asm format supported by gcc.
  162. file=netinet/in.h
  163. base=`basename $file`
  164. if [ -r ${LIB}/$file ]; then
  165.   file_to_fix=${LIB}/$file
  166. else
  167.   if [ -r ${INPUT}/$file ]; then
  168.     file_to_fix=${INPUT}/$file
  169.   else
  170.     file_to_fix=""
  171.   fi
  172. fi
  173. if [ \! -z "$file_to_fix" ]; then
  174.   echo Checking $file_to_fix
  175.   if grep __GNUC__ $file_to_fix > /dev/null; then
  176.     true
  177.   else
  178.     sed -e '/#define NETSWAP/a\
  179. \
  180. #if defined (__GNUC__) || defined (__GNUG__)\
  181. #include <sys/byteorder.h>\
  182. #else  /* not __GNUC__ */\
  183. ' \
  184.     -e '/#endif[     ]*\/\* NETSWAP \*\//i\
  185. #endif /* not __GNUC__ */' \
  186.     $file_to_fix > ${LIB}/${file}.sed
  187.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  188.     echo Fixed $file_to_fix
  189.   fi
  190. fi
  191.  
  192. exit 0
  193.  
  194.